package com.ctrip.ec.api.admin.controller.forward;
import com.ctrip.ec.api.admin.model.query.QueryModel;
import com.ctrip.ec.dal.PagerSetting;
import com.ctrip.ec.api.admin.common.RequestContext;
import com.ctrip.ec.biz.dao.forward.ForwardGoodsDao;
import com.ctrip.ec.biz.entity.forward.ForwardGoodsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.List;
@RestController
@RequestMapping("forwardGoods")
public class ForwardGoodsController{
    @Autowired
    private ForwardGoodsDao forwardGoods;

    @PostMapping("list")
    public List<ForwardGoodsEntity> list(@RequestBody QueryModel model) throws  SQLException{
        PagerSetting setting = model.build();
        List<ForwardGoodsEntity> list = forwardGoods.list(setting);
        RequestContext.setResponseHeaderCount(setting.getRecordCount());
        return list;
    }

    @GetMapping("detail/{id}")
    public  ForwardGoodsEntity detail(@PathVariable Long id) throws SQLException {
        return forwardGoods.entity(id);
    }

    @PostMapping("save")
    public  Long save(@RequestBody ForwardGoodsEntity entity) throws SQLException {
        forwardGoods.save(entity);
        return entity.getId();
    }

    @PostMapping("delete")
    public  void delete(@RequestBody List<Long> ids) throws SQLException {
        forwardGoods.delete(ids);
    }
    @PostMapping("erase")
    public void erase(@RequestBody List<Long> ids) throws  SQLException{
        forwardGoods.erase(ids);
    }

    @PostMapping("unerase")
    public  void unerase(@RequestBody List<Long> ids) throws  SQLException{
        forwardGoods.unerase(ids);
    }
}
